<template>
  <div id="app">
       <transition :name="transitionName">
          <keep-alive>
            <router-view  v-if="$route.meta.keepAlive"></router-view>
          </keep-alive>
        </transition>
        <transition :name="transitionName">
          <router-view  v-if="!$route.meta.keepAlive"></router-view>
        </transition>
  </div>
</template>

<script>
import axios from 'axios'
import Vue from'vue'
import { Toast } from 'vant';

Vue.use(Toast);
export default {
  name: 'App',
   data(){
    return {
      transitionName:'slide-left'
    }
  },
   beforeRouteUpdate (to, from, next) {
      console.log(to,from)
        if(this.$route.path!='/HomeView') //假设name为home的路由都使用`slide-left`,其它的路由都为`slider-right`
        {
            this.$router.isBack=true;
        }
      let isBack = this.$router.isBack
      console.log(this.$router)
      if (isBack) {
        this.transitionName = 'slide-right'
      } else {
        this.transitionName = 'slide-left'
      }
      this.$router.isBack = false
      next()
    },
  mounted () {
    this.getAxios()
  },
    methods:{
    getAxios:function () {
      //添加请求拦截器
      axios.interceptors.request.use(config => {
       const toast = Toast.loading({
          duration: 0,       // 持续展示 toast
          loadingType: 'circular',
          forbidClick: true, // 禁用背景点击  
        });

        return config
      }, error => {
//       this.loadingShow = true
        return Promise.reject(error)
      })

//添加响应拦截器
      axios.interceptors.response.use(response => {
        Toast.clear();
        return response
      }, error => {
//        console.log('2'+error)
        return Promise.reject(error)
      })
    }
  }
}
</script>

<style  scoped lang="scss">
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  // text-align: center;
  color: #2c3e50;
  width: 10rem;
  margin: 0 auto;
  height: 100%;
  // margin-top: 60px;
  // max-width:;
}




    .slide-left-enter-active {
  transition: all .3s ease;
}
.slide-left-leave-active {
  transition: all .8s ease  ;
}
.slide-left-enter, 
/* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateX(100%);
  opacity: 0;
}
.slide-left-leave-to{
 transform: translateX(-100%);
  opacity: 0;
}

.slide-right-enter-active {
  transition: all .3s ease;
}
.slide-right-leave-active {
  transition: all .8s ease  ;
}
.slide-right-enter, 
/* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateX(-100%);
  opacity: 0;
}
.slide-right-leave-to{
    transform: translateX(100%);
    opacity: 0;
}
</style>
